home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / demo / demosrc / d_contour.pro < prev    next >
Text File  |  1997-07-08  |  25KB  |  807 lines

  1. ; $Id: d_contour.pro,v 1.23 1997/04/21 22:05:15 tremblay Exp $
  2. ;
  3. ;  Copyright (c) 1997, Research Systems, Inc. All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5. ;
  6. ;+
  7. ;  FILE:
  8. ;       d_contour.pro
  9. ;
  10. ;  CALLING SEQUENCE: d_contour
  11. ;
  12. ;  PURPOSE:
  13. ;       Shows several feature of contour plots 
  14. ;       (direct and object graphics).
  15. ;
  16. ;  MAJOR TOPICS: Plots and widgets
  17. ;
  18. ;  CATEGORY:
  19. ;       IDL 5.0
  20. ;
  21. ;  INTERNAL FUNCTIONS and PROCEDURES:
  22. ;       fun GetColorArray          - Returns the color array
  23. ;       fun GetContourColor        - Returns the color of a given level
  24. ;       pro MakeBasic              - Create the basic contour plot
  25. ;       pro MakeColor              - Create the plot with colored lines
  26. ;       pro MakeFill               - Create the fill contour plot
  27. ;       pro MakeLinestyle          - Create the plot with various line stlyes
  28. ;       pro MakeAnnotation         - Create the plot with annotations
  29. ;       pro MakeFillAndLine        - Create the fill plot with overlaying lines
  30. ;       pro d_contour_Event            - Event handler
  31. ;       pro d_contourCleanup           - Cleanup
  32. ;       pro d_contour                  - Main procedure
  33. ;
  34. ;  EXTERNAL FUNCTIONS, PROCEDURES, and FILES:
  35. ;       pro gettips                - Get the tips text structure..
  36. ;       pro widtips                - Create the widget text for tips.
  37. ;       contr.txt
  38. ;       contr.tip
  39. ;       worldelv.dat
  40. ;
  41. ;  REFERENCE: IDL Reference Guide, IDL User's Guide
  42. ;
  43. ;  NAMED STRUCTURES:
  44. ;       none.
  45. ;
  46. ;  COMMON BLOCS:
  47. ;       none.
  48. ;
  49. ;  MODIFICATION HISTORY: Written by:  DAT, RSI,  December 96
  50. ;-
  51. ;--------------------------------------------------------------------
  52. ;
  53. ;   PURPOSE  Assign a color to the polyline
  54. ;
  55. function GetColorArray, $
  56.     highColor, $        ; IN: highest color index.
  57.     nLevels             ; IN: number of contour levels.
  58.  
  59.     if (nLevels eq 15) then begin
  60.         ColorArray = [0, 4, 11, 9, 3, 10, 5, 8, 2, 6, 13, 12, 14, 15, 1 ]
  61.     endif else if (nLevels eq 11) then begin
  62.         ColorArray = [0, 11,  9, 10, 5, 8, 2, 6, 12,  15, 1 ]
  63.     endif else begin
  64.         ColorArray = [0, 11,   5, 8, 2,  15, 1 ]
  65.     endelse
  66.     ColorArray = colorArray + highColor
  67.  
  68.     RETURN, colorArray
  69.  
  70. end      ;   of  GetColorArray
  71.  
  72. ;--------------------------------------------------------------------
  73. ;
  74. ;   PURPOSE  Assign a color to the polyline
  75. ;
  76. function GetContourColor, $
  77.     level, $      ; IN: level index
  78.     nLevels       ; IN: number of levels
  79.  
  80.     highColor = !D.TABLE_SIZE-18 + 1
  81.     colorArray = GetColorArray( highColor, nLevels)
  82.     index = ColorArray[level] 
  83.     TVLCT, Red, Green, Blue,  /GET
  84.  
  85.   RETURN, [Red[index], Green[index], Blue[index]]
  86.  
  87. end
  88.  
  89. ;--------------------------------------------------------------------
  90. ;
  91. ;   PURPOSE  Create a contour plot with white solid lines
  92. ;            (direct graphics)
  93. ;
  94. pro MakeBasic, $
  95.     data, $           ; IN:  data (n by m)
  96.     WindowID, $       ; IN:  window identifier (pixmap)
  97.     DrawXSize, $      ; IN:  x dimension of drawing area
  98.     DrawYSize, $      ; IN:  y dimension of drawing area
  99.     highColor, $      ; IN   highest color index of color table
  100.     AX=ax, $          ; IN:  x rotation (in degree)
  101.     AZ=az, $          ; IN:  z rotation (in degree)
  102.     NLevels=nLevels   ; IN:  number of levels
  103.  
  104.  
  105.     LOADCT, 5, /SILENT
  106.     TEK_COLOR, !D.TABLE_SIZE-18, 16
  107.  
  108.     sf_x = (FLOAT(drawYSize) / FLOAT(drawXSize)) < 1.0
  109.     sf_y = (FLOAT(drawXSize) / FLOAT(drawYSize)) < 1.0
  110.  
  111.     WSET, windowID
  112.  
  113.     CONTOUR, data, COLOR=highColor+1, $
  114.         BACKGROUND=highColor, $
  115.         NLEVELS=nLevels, $
  116.         YTITLE='Latitude', XTITLE='Longitude', $
  117.         TITLE='World Elevation', $
  118.         XSTYLE=5, YSTYLE=5, TICKLEN=(-0.02), ZSTYLE=5
  119.     Empty
  120.  
  121.     CONTOUR, data, COLOR=highColor+1, $
  122.         NLEVELS=nLevels, /NODATA, $
  123.         BACKGROUND=highColor, $
  124.         XSTYLE=1, YSTYLE=1, TICKLEN=(-0.02), ZSTYLE=5, $
  125.         XTICKS=4, YTICKS=4, $
  126.         YTITLE='Latitude', XTITLE='Longitude', $
  127.         TITLE='World Elevation', $
  128.         XTICKNAME=['0', '90', '180', '270', '0'], $
  129.         YTICKNAME=['-90', '-45', '0', '+45', '+90'], $
  130.         /NOERASE
  131.     Empty
  132.  
  133. end
  134. ;--------------------------------------------------------------------
  135. ;
  136. ;   PURPOSE  Create a contour plot colored lines
  137. ;            (direct graphics)
  138. ;
  139. pro MakeColor, $
  140.     data, $           ; IN:  data (n by m)
  141.     WindowID, $       ; IN:  window identifier (pixmap)
  142.     DrawXSize, $      ; IN:  x dimension of drawing area
  143.     DrawYSize, $      ; IN:  y dimension of drawing area
  144.     highColor, $      ; IN   highest color index of color table
  145.     AX=ax, $          ; IN:  x rotation (in degree)
  146.     AZ=az, $          ; IN:  z rotation (in degree)
  147.     NLevels=nLevels   ; IN:  number of levels
  148.  
  149.  
  150.     LOADCT, 5, /SILENT
  151.     TEK_COLOR, !D.TABLE_SIZE-18, 16
  152.  
  153.     sf_x = (FLOAT(drawYSize) / FLOAT(drawXSize)) < 1.0
  154.     sf_y = (FLOAT(drawXSize) / FLOAT(drawYSize)) < 1.0
  155.  
  156.     WSET, windowID
  157.  
  158.     colorArray = GetColorArray(highColor, nLevels)
  159.  
  160.     CONTOUR, data, COLOR=highColor+17, $
  161.         BACKGROUND=highColor, $
  162.         C_COLORS=colorArray, NLEVELS=nLevels, $
  163.         YTITLE='Latitude', XTITLE='Longitude', $
  164.         TITLE='World Elevation', $
  165.         XSTYLE=5, YSTYLE=5, TICKLEN=(-0.02), ZSTYLE=5
  166.     Empty
  167.  
  168.     CONTOUR, data, COLOR=highColor+1, $
  169.         BACKGROUND=highColor, $
  170.         NLEVELS=nLevels, /NODATA, $
  171.         XSTYLE=1, YSTYLE=1, TICKLEN=(-0.02), ZSTYLE=5, $
  172.         XTICKS=4, YTICKS=4, $
  173.         YTITLE='Latitude', XTITLE='Longitude', $
  174.         TITLE='World Elevation', $
  175.         XTICKNAME=['0', '90', '180', '270', '0'], $
  176.         YTICKNAME=['-90', '-45', '0', '+45', '+90'], $
  177.         /NOERASE
  178.     Empty
  179.  
  180. end
  181.  
  182. ;--------------------------------------------------------------------
  183. ;
  184. ;   PURPOSE  Create a filled contour plot 
  185. ;            (direct graphics)
  186. ;
  187. pro MakeFill, $
  188.     data, $           ; IN:  data (n by m)
  189.     WindowID, $       ; IN:  window identifier (pixmap)
  190.     DrawXSize, $      ; IN:  x dimension of drawing area
  191.     DrawYSize, $      ; IN:  y dimension of drawing area
  192.     highColor, $      ; IN   highest color index of color table
  193.     AX=ax, $          ; IN:  x rotation (in degree)
  194.     AZ=az, $          ; IN:  z rotation (in degree)
  195.     NLevels=nLevels   ; IN:  number of levels
  196.  
  197.  
  198.     LOADCT, 5, /SILENT
  199.     TEK_COLOR, !D.TABLE_SIZE-18, 16
  200.  
  201.     sf_x = (FLOAT(drawYSize) / FLOAT(drawXSize)) < 1.0
  202.     sf_y = (FLOAT(drawXSize) / FLOAT(drawYSize)) < 1.0
  203.  
  204.     WSET, windowID
  205.  
  206.     colorArray = GetColorArray(highColor, nLevels)
  207.  
  208.     CONTOUR, data, COLOR=highColor+17, $
  209.         BACKGROUND=highColor, $
  210.         YTITLE='Latitude', XTITLE='Longitude', $
  211.         TITLE='World Elevation', $
  212.         C_COLORS=colorArray, NLEVELS=nLevels, /FILL, $
  213.         XSTYLE=5, YSTYLE=5, TICKLEN=(-0.02), ZSTYLE=5
  214.     Empty
  215.  
  216.     CONTOUR, data, COLOR=highColor+1, $
  217.         BACKGROUND=highColor, $
  218.         NLEVELS=nLevels, /NODATA, $
  219.         XSTYLE=1, YSTYLE=1, TICKLEN=(-0.02), ZSTYLE=5, $
  220.         XTICKS=4, YTICKS=4, $
  221.         YTITLE='Latitude', XTITLE='Longitude', $
  222.         TITLE='World Elevation', $
  223.         XTICKNAME=['0', '90', '180', '270', '0'], $
  224.         YTICKNAME=['-90', '-45', '0', '+45', '+90'], $
  225.         /NOERASE
  226.     Empty
  227.  
  228. end
  229.  
  230. ;--------------------------------------------------------------------
  231. ;
  232. ;   PURPOSE  Create a contour plot with varios linestyle 
  233. ;            (direct graphics)
  234. ;
  235. pro MakeLinestyle, $
  236.     data, $           ; IN:  data (n by m)
  237.     WindowID, $       ; IN:  window identifier (pixmap)
  238.     DrawXSize, $      ; IN:  x dimension of drawing area
  239.     DrawYSize, $      ; IN:  y dimension of drawing area
  240.     highColor, $      ; IN   highest color index of color table
  241.     AX=ax, $          ; IN:  x rotation (in degree)
  242.     AZ=az, $          ; IN:  z rotation (in degree)
  243.     NLevels=nLevels   ; IN:  number of levels
  244.  
  245.  
  246.     LOADCT, 5, /SILENT
  247.     TEK_COLOR, !D.TABLE_SIZE-18, 16
  248.  
  249.     sf_x = (FLOAT(drawYSize) / FLOAT(drawXSize)) < 1.0
  250.     sf_y = (FLOAT(drawXSize) / FLOAT(drawYSize)) < 1.0
  251.  
  252.     WSET, windowID
  253.     lineStyle = [0,1,2,3,4,5]
  254.  
  255.     CONTOUR, data, COLOR=highColor+1, $
  256.         BACKGROUND=highColor, $
  257.         NLEVELS=nLevels, $
  258.         YTITLE='Latitude', XTITLE='Longitude', $
  259.         TITLE='World Elevation', $
  260.         C_LINESTYLE=lineStyle, $
  261.         XSTYLE=5, YSTYLE=5, TICKLEN=(-0.02), ZSTYLE=5
  262.     Empty
  263.  
  264.     CONTOUR, data, COLOR=highColor+1, $
  265.         BACKGROUND=highColor, $
  266.         NLEVELS=nLevels, /NODATA, $
  267.         XSTYLE=1, YSTYLE=1, TICKLEN=(-0.02), ZSTYLE=5, $
  268.         XTICKS=4, YTICKS=4, $
  269.         YTITLE='Latitude', XTITLE='Longitude', $
  270.         TITLE='World Elevation', $
  271.         XTICKNAME=['0', '90', '180', '270', '0'], $
  272.         YTICKNAME=['-90', '-45', '0', '+45', '+90'], $
  273.         /NOERASE
  274.     Empty
  275.  
  276. end
  277.  
  278. ;--------------------------------------------------------------------
  279. ;
  280. ;   PURPOSE  Create a contour plot with annotations
  281. ;            (direct graphics)
  282. ;
  283. pro MakeAnnotation, $
  284.     data, $           ; IN:  data (n by m)
  285.     WindowID, $       ; IN:  window identifier (pixmap)
  286.     DrawXSize, $      ; IN:  x dimension of drawing area
  287.     DrawYSize, $      ; IN:  y dimension of drawing area
  288.     highColor, $      ; IN   highest color index of color table
  289.     AX=ax, $          ; IN:  x rotation (in degree)
  290.     AZ=az, $          ; IN:  z rotation (in degree)
  291.     NLevels=nLevels   ; IN:  number of levels
  292.  
  293.     ;  Use the Hersey font.
  294.     ;
  295.     !P.FONT = -1
  296.  
  297.     ;  Create 7 contour levels here.
  298.     ;
  299.     LOADCT, 5, /SILENT
  300.     TEK_COLOR, !D.TABLE_SIZE-18, 16
  301.  
  302.     WSET, windowID
  303.  
  304.  
  305.     ;  Define the levels and their corresponding 
  306.     ;  annotations which are the elevation in meters.
  307.     ;
  308.     levels = [42B, 84B, 105b, 125B, 145b, 169B, 213B]
  309.     annotation = STRTRIM(levels * 40 - 5000, 2)
  310.     nLevels = N_ELEMENTS(levels)
  311.  
  312.     colorArray = GetColorArray(highColor, nLevels)
  313.  
  314.     CONTOUR, data, COLOR=highColor+1, $
  315.         BACKGROUND=highColor, $
  316.         NLEVELS=nLevels,  $
  317.         C_COLORS=colorArray, $
  318.         YTITLE='Latitude', XTITLE='Longitude', $
  319.         TITLE='World Elevation (in meters)', $
  320.         C_ANNOTATION=Annotation, /FOLLOW, C_CHARSIZE=1.25, $
  321.         XSTYLE=5, YSTYLE=5, TICKLEN=(-0.02), ZSTYLE=5
  322.     Empty
  323.  
  324.     CONTOUR, data, COLOR=highColor+1, $
  325.         BACKGROUND=highColor, $
  326.         NLEVELS=nLevels, /NODATA, $
  327.         XSTYLE=1, YSTYLE=1, TICKLEN=(-0.02), ZSTYLE=5, $
  328.         XTICKS=4, YTICKS=4, $
  329.         YTITLE='Latitude', XTITLE='Longitude', $
  330.         TITLE='World Elevation (in meters)', $
  331.         XTICKNAME=['0', '90', '180', '270', '0'], $
  332.         YTICKNAME=['-90', '-45', '0', '+45', '+90'], $
  333.         /NOERASE
  334.     Empty
  335.  
  336.     ;  Restore the hardware drawn font.
  337.     ;
  338.     !P.FONT = 0
  339.  
  340. end
  341.  
  342. ;--------------------------------------------------------------------
  343. ;
  344. ;   PURPOSE  Create a filled contour plot with lines 
  345. ;            (direct graphics)
  346. ;
  347. pro MakeFillAndLine, $
  348.     data, $           ; IN:  data (n by m)
  349.     WindowID, $       ; IN:  window identifier (pixmap)
  350.     DrawXSize, $      ; IN:  x dimension of drawing area
  351.     DrawYSize, $      ; IN:  y dimension of drawing area
  352.     highColor, $      ; IN   highest color index of color table
  353.     AX=ax, $          ; IN:  x rotation (in degree)
  354.     AZ=az, $          ; IN:  z rotation (in degree)
  355.     NLevels=nLevels   ; IN:  number of levels
  356.  
  357.  
  358.     LOADCT, 5, /SILENT
  359.     TEK_COLOR, !D.TABLE_SIZE-18, 16
  360.  
  361.     sf_x = (FLOAT(drawYSize) / FLOAT(drawXSize)) < 1.0
  362.     sf_y = (FLOAT(drawXSize) / FLOAT(drawYSize)) < 1.0
  363.  
  364.     WSET, windowID
  365.  
  366.     colorArray = GetColorArray(highColor, nLevels)
  367.  
  368.     CONTOUR, data, COLOR=highColor+17, $
  369.         BACKGROUND=highColor, $
  370.         YTITLE='Latitude', XTITLE='Longitude', $
  371.         TITLE='World Elevation', $
  372.         C_COLORS=colorArray, NLEVELS=nLevels, /FILL, $
  373.         XSTYLE=5, YSTYLE=5, TICKLEN=(-0.02), ZSTYLE=5
  374.  
  375.     CONTOUR, data, COLOR=highColor+17, $
  376.         BACKGROUND=highColor, $
  377.         NLEVELS=nLevels,  /OVERPLOT, FONT=-1
  378.  
  379.     Empty
  380.  
  381.     CONTOUR, data, COLOR=highColor+1, $
  382.         BACKGROUND=highColor, $
  383.         NLEVELS=nLevels, /NODATA, $
  384.         XSTYLE=1, YSTYLE=1, TICKLEN=(-0.02), ZSTYLE=5, $
  385.         XTICKS=4, YTICKS=4, $
  386.         YTITLE='Latitude', XTITLE='Longitude', $
  387.         TITLE='World Elevation', $
  388.         XTICKNAME=['0', '90', '180', '270', '0'], $
  389.         YTICKNAME=['-90', '-45', '0', '+45', '+90'], $
  390.         /NOERASE
  391.     Empty
  392.  
  393. end
  394.  
  395. ;--------------------------------------------------------------------
  396. ;
  397. ;   PURPOSE  Handle the event
  398. ;
  399. pro d_contour_Event, $
  400.     sEvent        ; IN: event structure
  401.  
  402.     if (TAG_NAMES(sEvent, /STRUCTURE_NAME) EQ $
  403.         'WIDGET_KILL_REQUEST') then begin
  404.         WIDGET_CONTROL, sEvent.top, /DESTROY
  405.         RETURN
  406.     endif
  407.  
  408.  
  409.     WIDGET_CONTROL, sEvent.id, GET_UVALUE=eventUValue
  410.     eventName = WIDGET_INFO(sEvent.id,/NAME)
  411.  
  412.     ;  Handle the event for the direct graphics or the slider.
  413.     ;
  414.     if ( (eventUValue eq 'SELECTD') or $
  415.         (eventUValue eq 'NLEVELS') ) then begin
  416.  
  417.         WIDGET_CONTROL, sEvent.top, GET_UVALUE=sInfo, /NO_COPY
  418.         WIDGET_CONTROL, sInfo.wLevelSlider, GET_VALUE=levelValue
  419.  
  420.         ;  Here, level value is 1, 2, or 3. We want to
  421.         ;  have the number of levels to be 7, 11, or 15.
  422.         ;
  423.         sInfo.nLevels = levelValue*4 + 3
  424.         WIDGET_CONTROL, sInfo.wSelectDButton, GET_VALUE=selection
  425.         WSET, sInfo.drawDWindowID
  426.  
  427.         WIDGET_CONTROL, sInfo.wLevelLabel, $
  428.             SET_VALUE=STRING(sInfo.nLevels, FORMAT='(i2)')
  429.  
  430.         case selection of
  431.  
  432.             ;  Create the basic contour
  433.             ;
  434.             0 : begin
  435.                 WIDGET_CONTROL, sInfo.wLevelSlider, SENSITIVE=1
  436.                 MakeBasic , sInfo.data, sInfo.drawDWindowID, $
  437.                     sInfo.drawXSize, sInfo.drawYSize, $
  438.                     sInfo.highColor, $
  439.                     AX=sInfo.xRotation, AZ=sInfo.zRotation, $
  440.                     NLEVELS=sInfo.nlevels
  441.             end
  442.  
  443.             ;  Create the contour with colored lines.
  444.             ;
  445.             1 : begin
  446.                 WIDGET_CONTROL, sInfo.wLevelSlider, SENSITIVE=1
  447.                 MakeColor , sInfo.data, sInfo.drawDWindowID, $
  448.                     sInfo.drawXSize, sInfo.drawYSize, $
  449.                     sInfo.highColor, $
  450.                     AX=sInfo.xRotation, AZ=sInfo.zRotation, $
  451.                     NLEVELS=sInfo.nlevels
  452.             end
  453.  
  454.             ;  Create filled contour plot.
  455.             ;
  456.             2 : begin
  457.                 WIDGET_CONTROL, sInfo.wLevelSlider, SENSITIVE=1
  458.                 MakeFill , sInfo.data, sInfo.drawDWindowID, $
  459.                     sInfo.drawXSize, sInfo.drawYSize, $
  460.                     sInfo.highColor, $
  461.                     AX=sInfo.xRotation, AZ=sInfo.zRotation, $
  462.                     NLEVELS=sInfo.nlevels
  463.             end
  464.  
  465.             ;  Create contour lines with vaious line styles.
  466.             ;
  467.             3 : begin
  468.                 WIDGET_CONTROL, sInfo.wLevelSlider, SENSITIVE=1
  469.                 MakeLinestyle , sInfo.data, sInfo.drawDWindowID, $
  470.                     sInfo.drawXSize, sInfo.drawYSize, $
  471.                     sInfo.highColor, $
  472.                     AX=sInfo.xRotation, AZ=sInfo.zRotation, $
  473.                     NLEVELS=sInfo.nlevels
  474.             end
  475.  
  476.             ;  Create contour with annotations.
  477.             ;
  478.             4 : begin
  479.                 WIDGET_CONTROL, sInfo.wLevelSlider, SENSITIVE=0
  480.                 MakeAnnotation , sInfo.data, sInfo.drawDWindowID, $
  481.                     sInfo.drawXSize, sInfo.drawYSize, $
  482.                     sInfo.highColor, $
  483.                     AX=sInfo.xRotation, AZ=sInfo.zRotation, $
  484.                     NLEVELS=7
  485.             end
  486.  
  487.             ;  Create filled contour with overlaying lines.
  488.             ;
  489.             5 : begin
  490.                 WIDGET_CONTROL, sInfo.wLevelSlider, SENSITIVE=1
  491.                 MakeFillAndLine , sInfo.data, sInfo.drawDWindowID, $
  492.                     sInfo.drawXSize, sInfo.drawYSize, $
  493.                     sInfo.highColor, $
  494.                     AX=0, AZ=0, $
  495.                     NLEVELS=sInfo.nlevels
  496.             end
  497.                     
  498.         endcase
  499.          
  500.         WIDGET_CONTROL, sEvent.top, SET_UVALUE=sInfo, /NO_COPY
  501.  
  502.     ;  Handle all the other possible events.
  503.     ;
  504.     endif else begin
  505.        
  506.         case eventUValue of
  507.             
  508.             ;  Quit his application.
  509.             ;
  510.             'QUIT' : begin
  511.                 WIDGET_CONTROL, sEvent.top, /DESTROY
  512.             end
  513.  
  514.             ;  Display the information file.
  515.             ;
  516.             'ABOUT' : begin
  517.                 if( Xregistered('XDisplayFile') ne 0) then RETURN
  518.                 XDisplayFile, filepath('contr.txt', $
  519.                     SUBDIR=['examples','demo','demotext']), $
  520.                     DONE_BUTTON='Done', $
  521.                     TITLE="About contour plots" , $
  522.                     GROUP=sEvent.top, WIDTH=55, HEIGHT=14
  523.             end           ;  of ABOUT
  524.  
  525.             ELSE :   ;  do nothing
  526.    
  527.         endcase   ;  of eventUValue
  528.  
  529.     endelse
  530.         
  531. end     ;   of d_contour_Event
  532.  
  533. ;--------------------------------------------------------------------
  534. ;
  535. pro D_ContourCleanup, wTopBase
  536.  
  537.     ;  Get the color table saved in the window's user value.
  538.     ;
  539.     WIDGET_CONTROL, wTopBase, GET_UVALUE=sInfo,/No_Copy
  540.    
  541.     ;  Restore the previous color table.
  542.     ;
  543.     TVLCT, sInfo.colorTable
  544.  
  545.     ;  Restore the previous plot font.
  546.     ;
  547.     !P.FONT = sInfo.plotFont
  548.     
  549.     ;  Delete the pixmap.
  550.     ;
  551.     for i = 0, sInfo.nPixmap-1 do begin
  552.         WDELETE, sInfo.pixmapArray[i]
  553.     endfor
  554.  
  555.     ;  Restore default margins.
  556.     ;
  557.     !X.MARGIN = [10, 3]
  558.     !Y.MARGIN = [4, 2]
  559.  
  560.     if WIDGET_INFO(sInfo.groupBase, /VALID_ID) then $
  561.         WIDGET_CONTROL, sInfo.groupBase, /MAP
  562.  
  563. end   ; of CleanupForecast
  564.  
  565. ;--------------------------------------------------------------------
  566. ;
  567. ;   PURPOSE 
  568. ;
  569. pro D_Contour, $
  570.     GROUP=group, $   ; IN: (opt) group identifier
  571.     APPTLB = appTLB    ; OUT: (opt) TLB of this application
  572.  
  573.     ;  Check the validity of the group identifier.
  574.     ;
  575.     ngroup = N_ELEMENTS(group)
  576.     if (ngroup NE 0) then begin
  577.         check = WIDGET_INFO(group, /VALID_ID)
  578.         if (check NE 1) then begin
  579.             print,'Error, the group identifier is not valid'
  580.             print, 'Return to the main application'
  581.             RETURN
  582.         endif
  583.         groupBase = group
  584.     endif else groupBase = 0L
  585.  
  586.     ;  Get the current color table. It will be restored when exiting.
  587.     ;
  588.     TVLCT, savedR, savedG, savedB, /GET
  589.     colorTable = [[savedR],[savedG],[savedB]]
  590.  
  591.     ;  Get the screen size.
  592.     ;
  593.     DEVICE, GET_SCREEN_SIZE = screenSize
  594.  
  595.     ;  Create the starting up message.
  596.     ;
  597.     drawbase = startmes(GROUP=groupBase)
  598.  
  599.     ;  Also save the font.
  600.     ;
  601.     plotFont = !P.FONT
  602.     
  603.     ; Get the character scaling factor.
  604.     ;
  605.     charscale = 8.0/!d.X_CH_SIZE
  606.  
  607.     ;  Load a new color table.
  608.     ;
  609.     LOADCT, 5, /SILENT
  610.     highColor = !D.TABLE_SIZE-18
  611.     TEK_COLOR, highColor+1, 16
  612.  
  613.     ;  Use hardware-drawn font.
  614.     ;
  615.     !P.FONT=0
  616.  
  617.     ;  Set up the drawing area size.
  618.     ;
  619.     drawXSize = 0.6 * screenSize[0]
  620.     drawYSize = 0.8 * drawXSize
  621.     
  622.     ;  Set the rotation degrees of x and z axes.
  623.     ;  Set the initial number of contour levels.
  624.     ;
  625.     xRotation = 0
  626.     zRotation = 0
  627.     nLevels = 15
  628.  
  629.     ;  Get the tips.
  630.     ;
  631.     sText = getTips(filepath('contr.tip', $
  632.         SUBDIR=['examples','demo', 'demotext']) )
  633.  
  634.     ;  Create the widgets.
  635.     ;
  636.     wTopBase = WIDGET_BASE(TITLE="Contour Plot / World Elevation", $
  637.         /TLB_KILL_REQUEST_EVENTS, $
  638.         MAP=0, $
  639.         /COLUMN, GROUP_LEADER=groupBase, $
  640.         TLB_FRAME_ATTR = 1, MBAR=barBase)
  641.  
  642.  
  643.         ;  Create the menu bar items.
  644.         ;
  645.         wFileButton = WIDGET_BUTTON(barBase, VALUE='File')
  646.           
  647.             wQuitButton = WIDGET_BUTTON(wFileButton, VALUE='Quit', $
  648.                 UVALUE='QUIT')
  649.  
  650.         wHelpButton = WIDGET_BUTTON(barBase, VALUE='About', /HELP)
  651.           
  652.             wAboutButton = WIDGET_BUTTON(wHelpButton, $
  653.                 VALUE='About contours', $
  654.                 UVALUE='ABOUT')
  655.                 
  656.         ;  Create 2 selections bases : direct and object graphics.
  657.         ;
  658.         wSelectionBase = LONARR(2)  
  659.         wTempBase = WIDGET_BASE(wTopbase)
  660.         for i=0, N_ELEMENTS(wSelectionbase)-1 do  begin
  661.             wSelectionbase[i] = WIDGET_BASE(wTempBase, $
  662.             UVALUE=0L, /COLUMN, MAP=0)
  663.         endfor
  664.  
  665.             ;  Create the left and right bases (direct graphics).
  666.             ;
  667.             wTopRowDBase = WIDGET_BASE(wSelectionBase[0], $
  668.                 UVALUE='DIRECT', COLUMN=2)
  669.         
  670.                 wLeftDBase = WIDGET_BASE(wTopRowDBase, /COLUMN)
  671.             
  672.                     wSelectDButton = CW_BGROUP(wLeftDBase, $
  673.                         ['Basic', 'Colored Lines', $
  674.                          'Fill', 'Linestyle',  $
  675.                         'Annotation', 'Fill and Lines'], $
  676.                         SET_VALUE=1, $
  677.                         UVALUE='SELECTD', /EXCLUSIVE,/NO_RELEASE)
  678.  
  679.                     wLevelLabel = WIDGET_LABEL(wLeftDBase, $
  680.                         VALUE='15', /ALIGN_CENTER)
  681.  
  682.                 
  683.                     wLevelSlider = WIDGET_SLIDER(wLeftDBase, $
  684.                         MINIMUM=1, MAXIMUM=3, VALUE=3, $
  685.                         /SUPPRESS_VALUE, $
  686.                         TITLE='Number of Levels', $
  687.                         UVALUE='NLEVELS')
  688.                 
  689.             wRightDBase = WIDGET_BASE(wTopRowDBase, /COLUMN)
  690.             
  691.                 wAreaDDraw = WIDGET_DRAW(wRightDBase, XSIZE=drawXSize, $
  692.                     YSIZE=drawYSize, RETAIN=2)
  693.  
  694.         ;  Create tips texts.
  695.         ;
  696.         wStatusBase = WIDGET_BASE(wTopBase, MAP=0, /ROW)
  697.         
  698.             nWidgets = 2
  699.             wText = LONARR(nWidgets)
  700.             widTips, wStatusBase, sText.text, XSIZE=36, $
  701.                 YSIZE=3, NWIDGETS=nWidgets, wText
  702.  
  703.     ;  Realize the widget hierarchy.
  704.     ;
  705.     WIDGET_CONTROL, wTopBase, /REALIZE
  706.  
  707.     ;  Returns the top level base to the APPTLB keyword.
  708.     ;
  709.     appTLB = wtopBase
  710.  
  711.     ;  Size the tips widgets.
  712.     ;
  713.     sizeTips, wTopBase, wText, wStatusBase
  714.     
  715.     WIDGET_CONTROL, wTopBase, SENSITIVE=0
  716.     WIDGET_CONTROL, wSelectDButton, SET_VALUE=0
  717.  
  718.     
  719.     ;  Determine the window value of plot window, wDraw1.
  720.     ;
  721.     WIDGET_CONTROL, wAreaDDraw, GET_VALUE=drawDWindowID
  722.  
  723.  
  724.     ;  Create 3 pixmaps.
  725.     ;
  726.     nPixmap = 1
  727.     pixmapArray = LONARR(nPixmap)
  728.     for i = 0, nPixmap-1 do begin
  729.         Window, /FREE, XSIZE=drawXSize, YSIZE=drawYSize, /PIXMAP
  730.         pixmapArray[i] = !D.Window
  731.     endfor
  732.  
  733.     ;  Open and read the world elevation data file.
  734.     ;
  735.     world_elev = BYTARR(360, 360, /Nozero)
  736.     GET_LUN, data_lun
  737.     OPENR, data_lun, filepath('worldelv.dat', $
  738.         SUBDIR=['examples', 'data'])
  739.     READU, data_lun, world_elev
  740.     CLOSE, data_lun
  741.     FREE_LUN, data_lun
  742.  
  743.     world_elev = REBIN(world_elev, 90, 45)
  744.  
  745.     data = world_elev
  746.     data2 = world_elev
  747.  
  748.     ;  Make the fill contour with line the default.
  749.     ;  of the direct graphics.
  750.     ;
  751.     MakeFillAndLine , data, drawDWindowID, $
  752.         drawXSize, drawYSize, highColor, $
  753.         AX=xRotation, AZ=zRotation, NLEVELS=nlevels
  754.  
  755.     ;  Destroy the starting up window.
  756.     ;
  757.     WIDGET_CONTROL, drawbase, /DESTROY
  758.  
  759.     ;  Map the top level base.
  760.     ;
  761.     WIDGET_CONTROL, wTopBase, MAP=1
  762.  
  763.     WIDGET_CONTROL, wSelectionBase[0], MAP=1
  764.     WIDGET_CONTROL, wSelectDButton, SET_VALUE=5
  765.  
  766.     ;  Create the info structure.
  767.     ;
  768.     sInfo = { $
  769.         SText: sText, $                     ; Text structure for tips
  770.         Data: data, $                       ; Elevation data
  771.         XRotation: xRotation, $             ; X axis rotation (direct graphics)
  772.         ZRotation: ZRotation, $             ; Z axis rotation (direct graphics)
  773.         NLevels: nLevels, $                 ; Number of contour levels
  774.         Highcolor: highColor, $             ; Color index of highest color.
  775.         CurrentBase: wSelectionBase[0], $   ; Indicates the current base
  776.         DrawXSize: drawXSize, $             ; X size of drawing area
  777.         DrawYSize: drawYSize, $             ; Y size of drawing area
  778.         ColorTable:colorTable, $            ; Color table to restore at exit
  779.         CharScale: charScale, $             ; Character scaling factor
  780.         NPixmap: nPixmap, $                 ; Number of pixmaps
  781.         PixmapArray: pixmapArray, $         ; Array of pixmap ID
  782.         DrawDWindowID: drawDWindowID, $     ; Direct graphics window ID
  783.         WTopBase: wTopBase, $               ; Top level base
  784.         WSelectDButton: wSelectDButton, $   ; Selection button ID
  785.         WLevelSlider: wLevelSlider, $       ; Number of contour level slider
  786.         WLevelLabel: wLevelLabel, $         ; Number of selected levels label
  787.         WSelectionBase: wSelectionBase, $   ; Slection base ID
  788.         WText: wText, $                     ; Widget text ID for tips
  789.         plotFont: plotFont, $               ; Font ID
  790.         groupBase: groupBase $              ; Base of Group Leader
  791.     }
  792.      
  793.     ;  Register the info structure
  794.     ;  in the user value of the top-level base.
  795.     ;
  796.     WIDGET_CONTROL, wTopBase, SET_UVALUE=sInfo, /NO_COPY
  797.      
  798.     WIDGET_CONTROL, wTopBase, SENSITIVE=1
  799.  
  800.     ; Register with the XMANAGER.
  801.     ;
  802.     XMANAGER, "D_Contour", wTopBase, $
  803.         /NO_BLOCK, $
  804.         EVENT_HANDLER = "D_Contour_Event",CLEANUP="D_ContourCleanup"
  805.     
  806. end                      ; of d_contour
  807.